Những câu hỏi liên quan
Khánh Linh
Xem chi tiết
Nguyễn Lê Phước Thịnh
1 tháng 3 2022 lúc 8:08

#include <bits/stdc++.h>

using namespace std;

long long a[1000],i,n;

int main()

{

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

for (i=1; i<=n; i++) cout<<a[i]<<"     ";

cout<<endl;

cout<<"Cac so duong la: ";

for (i=1; i<=n; i++) if (a[i]>0) cout<<a[i]<<" ";

cout<<endl;

for (i=1; i<=n; i++) if (a[i]%2==0) cout<<a[i]<<" ";

for (i=1; i<=n; i++) if (a[i]%2!=0) cout<<a[i]<<" ";

return 0;

}

Bình luận (0)
Khánh Linh
Xem chi tiết
Khánh Linh
Xem chi tiết
Khánh Linh
Xem chi tiết
Khánh Linh
Xem chi tiết
Nguyễn Lê Phước Thịnh
25 tháng 2 2022 lúc 8:21

#include <bits/stdc++.h>

using namespace std;

long long a[10000],i,n;

int main()

{

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

for (i=1; i<=n; i++) cout<<a[i]<<"     ";

cout<<endl;

t=0;

for (i=1; i<=n; i++) if (a[i]%2==0) t+=a[i];

cout<<"Tong cac so chan la: "<<t<<endl;

sort(a+1,a+n+1);

cout<<"Day so giam dan la: ";

for (i=n; i>=1; i--) cout<<a[i]<<" ";

return 0;

}

Bình luận (1)
Khánh Linh
Xem chi tiết
Nguyễn Lê Phước Thịnh
26 tháng 2 2022 lúc 22:53

Bài 2: 

#include <bits/stdc++.h>

using namespace std;

long long a[1000],i,n,ln,nn;

int main()

{

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

for (i=1; i<=n; i++) cout<<a[i]<<"     ";

cout<<endl;

ln=a[1];

nn=a[1];

for (i=2; i<=n; i++)

{

ln=max(ln,a[i]);

nn=min(nn,a[i]);

}

cout<<ln<<" "<<nn;

}

Bình luận (0)
Khánh Linh
Xem chi tiết
Nguyễn Lê Phước Thịnh
21 tháng 2 2022 lúc 20:07

uses crt;

var a:array[1..100]of integer;

i,n,t,j,tam:integer;

begin

clrscr;

readln(n);

for i:=1 to n do readln(a[i]);

for i:=1 to n do write(a[i]:5);

writeln;

writeln('Cac so duong la: ');

for i:=1 to n do if (a[i]>0) then write(a[i]:4);

writeln;

t:=0;

for i:=1 to n do 

  if a[i] mod 3=0 then t:=t+a[i];

writeln(t);

for i:=1 to n-1 do 

  for j:=i+1 to n do

if a[i]<a[j] then

begin

tam:=a[i];

a[i]:=a[j];

a[j]:=tam;

end;

for i:=1 to n  do write(a[i]:4);

readln;

end.

Bình luận (0)
Lê Thị Bảo Trâm
Xem chi tiết
Trần Đức Huy
6 tháng 2 2022 lúc 11:49

Chương trình nhập n và mảng hay nhập mảng chưa biết số hạng tử v

Bình luận (0)
Nguyễn Lê Phước Thịnh
6 tháng 2 2022 lúc 12:43

#include <bits/stdc++.h>

using namespace std;

long long a[1000],n,i,ln,t1,dem,s;

int main()

{

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

ln=a[1];

for (i=1; i<=n; i++) ln=max(ln,a[i]);

cout<<ln<<endl;

t=0;

for (i=1; i<=n; i++) if (a[i]%2==0) t=t+a[i];

cout<<t<<endl;

dem=0;

for (i=1; i<=n; i++) if (a[i]<0) dem++;

cout<<dem<<" ";

s=1;

for (i=1; i<=n; i++)

if ((a[i]%3==0) and (a[i]>0)) s=s*a[i];

cout<<s;

return 0;

}

Bình luận (1)
Kiều Vũ Linh
7 tháng 2 2022 lúc 8:37

Var a:array[1..200] of integer;

i,n,max,s1,dem,s2:integer;

begin

write('Nhap so luong phan tu cua mang n = ');readln(n);

for i:=1 to n do

begin

write('Nhap phan tu thu ',i,' = ');readln(a[i]);

end;

max:=a[1];

for i:=2 to n do

if a[i] > max then max:=a[i];

for i:=1 to n do

begin

if a[i] mod 2 = 0 then s1:=s1+a[i];

end;

for i:=1 to n do

begin

if a[i] < 0 then dem:=dem + 1;

end;

s2:=1;

for i:=1 to n do

begin

if (a[i] > 0) and (a[i] mod 3 = 0) then s2:=s2*a[i];

end;

writeln('gia tri lon nhat trong mang la ',max);

writeln('tong cac so chan la ',s1);

writeln('Co ',dem,' so am');

write('tich cac so duong va chia het cho 3 la ',s2);

end;

readln;

end.

Bình luận (0)
bui pham phuong Uyen
Xem chi tiết
Nguyễn Lê Phước Thịnh
27 tháng 1 2021 lúc 13:15

Bài 1: 

uses crt;

var a:array[1..100]of integer;

i,n,kt,max,x,j,tam:integer;

begin

clrscr;

write('Nhap n='); readln(n);

for i:=1 to n do 

  begin

write('A[',i,']='); readln(a[i]);

end;

writeln('Mang ban vua nhap la: ');

for i:=1 to n do 

  write(a[i]:4);

writeln;

for i:=1 to n-1 do 

  for j:=i+1 to n do 

if a[i]>a[j] then 

begin

tam:=a[i];

a[i]:=a[j];

a[j]:=tam;

end;

writeln('Day tang dan la: ');

for i:=1 to n do 

  write(a[i]:4);

writeln;

write('Nhap x='); readln(x);

max:=0;

kt:=0;

for i:=1 to n do 

  if (a[i] mod 2=0) and (a[i]<=x) then 

   begin

  if max<a[i] then max:=a[i];

kt:=1;

end;

if kt=0 then writeln('Trong day khong co so le')

else writeln('So chan lon nhat khong vuot qua ',x,' la: ',max);

readln;

end.

Bình luận (0)